package com.ddd.app.user.assembler;

import com.ddd.client.user.dto.command.UserModifyCmd;
import com.ddd.client.user.dto.command.UserRegisterCmd;
import com.ddd.client.user.dto.co.UserCO;
import com.ddd.domain.user.model.entity.UserEntity;
import com.ddd.domain.user.model.vo.UserPassword;

/**
 * User Application层转换器
 * 用于DTO与实体之间的互转
 *  TODO 可使用 mapstruct 代替
 *
 * @author guowm
 */
public class UserAssembler {
    public static UserEntity toEntity(UserRegisterCmd userRegisterCmd) {
        UserEntity userEntity = new UserEntity();
        userEntity.setUsername(userRegisterCmd.getUsername());
        userEntity.setPassword(new UserPassword(userRegisterCmd.getPassword()));
        userEntity.setName(userRegisterCmd.getName());
        userEntity.setMobile(userRegisterCmd.getMobile());
        userEntity.setGender(userRegisterCmd.getGender());
        userEntity.setBirthday(userRegisterCmd.getBirthday());
        userEntity.setDescription(userRegisterCmd.getDescription());

        return userEntity;
    }

    public static UserEntity toEntity(UserModifyCmd userModifyCmd) {
        UserEntity userEntity = new UserEntity();
        userEntity.setId(userModifyCmd.getId());
        userEntity.setUsername(userModifyCmd.getUsername());
        userEntity.setName(userModifyCmd.getName());
        userEntity.setMobile(userModifyCmd.getPhoneNo());
        userEntity.setGender(userModifyCmd.getGender());
        userEntity.setBirthday(userModifyCmd.getBirthday());
        userEntity.setDescription(userModifyCmd.getDescription());

        return userEntity;
    }

    public static UserCO toValueObject(UserEntity userEntity) {
        UserCO userCO = new UserCO();
        userCO.setId(userEntity.getId());
        userCO.setName(userEntity.getName());
        userCO.setUsername(userEntity.getUsername());
        userCO.setMobile(userEntity.getMobile());
        userCO.setGender(userEntity.getGender());
        userCO.setBirthday(userEntity.getBirthday());
        userCO.setDescription(userEntity.getDescription());

        return userCO;
    }
}
